﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="AdminGroupManage.aspx.cs" Inherits="Basic_Background_AdminGroupManage" %>
<script type="text/javascript">
window.addEvent('domready',function(){

window.showAdminGroupUpdateForm=function(r){
    var adminGroupData=adminGroupListDatagrid.getDataByRow(r);
    var form=$('formAdminGroupUpdate');
    form.getElement('.groupId').set('value',adminGroupData.groupId);
    form.getElement('.adminGroupName').set('value',adminGroupData.groupName);
    
    MUI.openContentByWindow('windowAdminGroupUpdate','修改系统用户组',$('formContainer'),$('formAdminGroupUpdate'),760,300);
    MUI.showModalMessage('正在获取系统权限资源');
    new Request.JSON({url:'RoleGroupManage.aspx?Action=search',noCache:true,onSuccess:function(result){
        if(result.error)
            MUI.appendStatusMessage({'text':result.msg});
        else
        {
            
            var data=result.data;
            var ul=$('adminGroupUpdateTabs');
            var content=$('adminGroupUpdateTabsContent');
            var html='',html2='';
            for(var i=0;i<data.length;i++)
            {
                if(i==0)
                {
                    html+='<li class="selected"><a href="adminGroupUpdateTabsContent'+i.toString()+'" title="'+data[i].roleGroupName+'">'+data[i].roleGroupName+'</a></li>';
                    html2+='<div id="adminGroupUpdateTabsContent'+i.toString()+'" class="tabsContent" style="line-height:25px;">';
                }
                else
                {
                    html+='<li><a href="adminGroupUpdateTabsContent'+i.toString()+'" title="'+data[i].roleGroupName+'">'+data[i].roleGroupName+'</a></li>';
                    html2+='<div id="adminGroupUpdateTabsContent'+i.toString()+'" class="tabsContent" style="line-height:25px;display:none;">';
                }
                html2+='<input type="checkbox" onclick="if(this.checked){$(\'adminGroupUpdateTabsContent'+i.toString()+'\').getElements(\'input[type=checkbox]\').set(\'checked\',true);}else{$(\'adminGroupUpdateTabsContent'+i.toString()+'\').getElements(\'input[type=checkbox]\').set(\'checked\',false);}" /><span style="margin:0 15px 0 3px;">选择该组所有权限</span><br/>'
                for(var j=0;j<data[i].roles.length;j++)
                {
                    if((','+adminGroupData.roleNames).indexOf(data[i].roles[j].roleName+',')>0)
                        html2+='<input type="checkbox" name="roleIds" value="'+data[i].roles[j].roleId+'" checked="checked" />';
                    else
                        html2+='<input type="checkbox" name="roleIds" value="'+data[i].roles[j].roleId+'" />';
                    html2+='<span style="margin:0 15px 0 3px;">'+data[i].roles[j].roleName+'</span>';
                }
                html2+='</div>';
            }
            ul.set('html',html);
            content.set('html',html2);
            MochaUI.initializeTabs('adminGroupUpdateTabs', 'adminGroupUpdateTabsContent');
        }
        MUI.hideModalMessage();
    },onFailure:function(error){
        MUI.appendStatusMessage({'text':'AJAX提交表单的过程中发生未知错误。'});
        MUI.hideModalMessage();
    }}).get();
};

window.showAdminUpdateAddForm=function(){
    MUI.openContentByWindow('windowAdminGroupAdd','添加系统用户组',$('formContainer'),$('formAdminGroupAdd'),760,300);
    MUI.showModalMessage('正在获取系统权限资源');
    new Request.JSON({url:'RoleGroupManage.aspx?Action=search',noCache:true,onSuccess:function(result){
        if(result.error)
            MUI.appendStatusMessage({'text':result.msg});
        else
        {
            var data=result.data;
            var ul=$('adminGroupAddTabs');
            var content=$('adminGroupAddTabsContent');
            var html='',html2='';
            for(var i=0;i<data.length;i++)
            {
                if(i==0)
                {
                    html+='<li class="selected"><a href="adminGroupAddTabsContent'+i.toString()+'" title="'+data[i].roleGroupName+'">'+data[i].roleGroupName+'</a></li>';
                    html2+='<div id="adminGroupAddTabsContent'+i.toString()+'" class="tabsContent" style="line-height:25px;">';
                }
                else
                {
                    html+='<li><a href="adminGroupAddTabsContent'+i.toString()+'" title="'+data[i].roleGroupName+'">'+data[i].roleGroupName+'</a></li>';
                    html2+='<div id="adminGroupAddTabsContent'+i.toString()+'" class="tabsContent" style="line-height:25px;display:none;">';
                }
                html2+='<input type="checkbox" onclick="if(this.checked){$(\'adminGroupAddTabsContent'+i.toString()+'\').getElements(\'input[type=checkbox]\').set(\'checked\',true);}else{$(\'adminGroupAddTabsContent'+i.toString()+'\').getElements(\'input[type=checkbox]\').set(\'checked\',false);}" /><span style="margin:0 15px 0 3px;">选择该组所有权限</span><br/>'
                for(var j=0;j<data[i].roles.length;j++)
                {
                    html2+='<input type="checkbox" name="roleIds" value="'+data[i].roles[j].roleId+'" /><span style="margin:0 15px 0 3px;">'+data[i].roles[j].roleName+'</span>';
                }
                html2+='</div>';
            }
            ul.set('html',html);
            content.set('html',html2);
            MochaUI.initializeTabs('adminGroupAddTabs', 'adminGroupAddTabsContent');
        }
        MUI.hideModalMessage();
    },onFailure:function(error){
        MUI.appendStatusMessage({'text':'AJAX提交表单的过程中发生未知错误。'});
        MUI.hideModalMessage();
    }}).get();
};

window.deleteAdminGroup=function(adminGroupId){
    MUI.showConfirm('您确定要删除所选定的行？',function(){
        MUI.showModalMessage('正在修改系统用户组');
        new Request.JSON({url:'AdminGroupManage.aspx?Action=deleteAdminGroup&adminGroupId='+adminGroupId.toString(),noCache:true,onSuccess:function(result){
            if(result.error)
                MUI.appendStatusMessage({'text':result.msg});
            else
            {
                MUI.appendStatusMessage({'text':result.msg});
                window.adminGroupListDatagrid.loadData();
            }
            MUI.hideModalMessage();
        },onFailure:function(error){
	        MUI.appendStatusMessage({'text':'AJAX提交表单的过程中发生未知错误。'});
	        MUI.hideModalMessage();
        }}).get();
    });
};

window.adminGroupUpdateFormCheck=function(){
    new FormCheck('formAdminGroupUpdate',{display:{tipsPosition:'left'},submit:false,onValidateSuccess:function(){
        MUI.showModalMessage('正在修改系统用户组');
        new Request.JSON({url:'AdminGroupManage.aspx?Action=updateAdminGroup',noCache:true,onSuccess:function(result){
            if(result.error)
                MUI.appendStatusMessage({'text':result.msg});
            else
            {
                $('windowAdminGroupUpdate').retrieve('instance').close();
                MUI.appendStatusMessage({'text':result.msg});
                window.adminGroupListDatagrid.loadData();
            }
            MUI.hideModalMessage();
	    },onFailure:function(error){
		    MUI.appendStatusMessage({'text':'AJAX提交表单的过程中发生未知错误。'});
		    MUI.hideModalMessage();
        }}).post($('formAdminGroupUpdate'));
    }});   
};

window.adminGroupAddFormCheck=function(){
    new FormCheck('formAdminGroupAdd',{display:{tipsPosition:'left'},submit:false,onValidateSuccess:function(){
        MUI.showModalMessage('正在添加系统用户组');
        new Request.JSON({url:'AdminGroupManage.aspx?Action=addAdminGroup',noCache:true,onSuccess:function(result){
            if(result.error)
                MUI.appendStatusMessage({'text':result.msg});
            else
            {
                $('windowAdminGroupAdd').retrieve('instance').close();
                MUI.appendStatusMessage({'text':result.msg});
                window.adminGroupListDatagrid.loadData();
            }
            MUI.hideModalMessage();
	    },onFailure:function(error){
		    MUI.appendStatusMessage({'text':'AJAX提交表单的过程中发生未知错误。'});
		    MUI.hideModalMessage();
        }}).post($('formAdminGroupAdd'));
    }});
};

window.accordionAdminGroup=function(obj){
    var data=window.adminGroupListDatagrid.getDataByRow(obj.row);
    var returnStr='';
    for(var i=0;i<data.admins.length;i++)
    {
        returnStr+=data.admins[i].adminName+',';
    }
    obj.parent.set('html',Util.setHtmlInFixedTable('该用户组的用户列表：<br />'+returnStr));
};

window.initializeAdminGroupManage=function(){
    new ZebraTable({elements:'table.tableFixed'});
    window.adminGroupListDatagrid = new omniGrid('adminGroupList', {
        columnModel: [
        {header: 'ID',dataIndex: 'groupId',dataType:'number',width:80},
        {header: '用户组名称',dataIndex: 'groupName',dataType:'string',width:120},
        {header: '是否锁定',dataIndex: 'isLockedDescription',dataType:'string',width:80},
        {header: '操作',dataIndex: 'adminId',dataType:'number',width:80,labelFunction:function(rowdata, r, columnModel){
            if(rowdata.isLocked==0)
                return '<a href="#" onclick="window.showAdminGroupUpdateForm('+r.toString()+');">修改</a>&nbsp;&nbsp;<a href="#" onclick="window.deleteAdminGroup('+rowdata.groupId+');">删除</a>';
            else
                return '&nbsp;';
        }}
        ],
        buttons : [
            {name: '添加', bclass: 'add', onclick : window.showAdminUpdateAddForm}
        ],
        url:"AdminGroupManage.aspx?Action=search&isadmin=1",
        perPageOptions: [20,50,100,200,500,1000],
        perPage:20,
        accordion:true,
		accordionRenderer:window.accordionAdminGroup,
		openAccordionOnDblClick:true,
        height:$('workspace').getStyle('height').toInt()-17,
        selectable:false,
        serverSort:false,
        sortHeader:false,
        pagination:true
    });
    //该页面目前没有这两个方法.
//    window.binddingEventAdminManage();
    window.adminGroupAddFormCheck();
    window.adminGroupUpdateFormCheck();
};

window.initializeAdminGroupManage();
});
</script>
<div id="adminGroupList"></div>
<div id="formContainer" style="display:none;">
<form id="formAdminGroupAdd">
<table class="tableFixed" border="0" cellpadding="0" cellspacing="0" width="100%">
    <tr>
        <td class="tableLeft1">用户组名：</td>
        <td class="tableLeft2"><input class="input validate['required','length[2,16]']" name="adminGroupName" type="text" /></td>
    </tr>
    <tr>
        <td class="tableLeft1"></td>
        <td class="tableLeft2"><input class="submit button validate['submit']" type="button" value="提交添加" /></td>
    </tr>
</table>
<div class="toolbarTabs">
    <ul id="adminGroupAddTabs" class="tab-menu">
	</ul>
	<div class="clear"></div>
</div>
<div id="adminGroupAddTabsContent"></div>
</form>
<form id="formAdminGroupUpdate">
<input class="groupId" type="hidden" name="groupId" />
<table class="tableFixed" border="0" cellpadding="0" cellspacing="0" width="100%">
    <tr>
        <td class="tableLeft1">用户组名：</td>
        <td class="tableLeft2"><input class="adminGroupName input validate['required','length[2,16]']" name="adminGroupName" type="text" /></td>
    </tr>
    <tr>
        <td class="tableLeft1"></td>
        <td class="tableLeft2"><input class="submit button validate['submit']" type="button" value="提交修改" /></td>
    </tr>
</table>
<div class="toolbarTabs">
    <ul id="adminGroupUpdateTabs" class="tab-menu">
	</ul>
	<div class="clear"></div>
</div>
<div id="adminGroupUpdateTabsContent"></div>
</form>
</div>